package com.geovis.emergency.spd.util;

import org.geotools.geojson.GeoJSONUtil;
import org.geotools.geojson.geom.GeometryJSON;
import org.locationtech.jts.geom.Geometry;

import java.io.IOException;
import java.io.Reader;

/**
 * <p>
 * geo工具类
 * </p>
 *
 * @author Lonsho
 * @version 1.0
 * @date 2022/6/9
 */
public class GeoUtil {
    /**
     * 将GeoJson转成WKT string
     * @param jsonString
     * @return
     */
    public static String geoJsonToWKT(String jsonString){
        try {
            GeometryJSON geometryJSON = new GeometryJSON();
            Reader reader = GeoJSONUtil.toReader(jsonString);
            Geometry geometry = geometryJSON.read(reader);
            return geometry.toText();
        }catch (IOException e){
            return null;
        }
    }
}
